home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / cc68x.zoo / utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  1.2 KB  |  71 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include "global.h"
  4.  
  5. void *mallok(n)
  6.   size_t n;
  7. {
  8.   void *r = malloc(n);
  9.  
  10.   if (!r)
  11.     fatal("Out of memory -- cannot allocate %ld bytes", (unsigned long)n);
  12.   return r;
  13. }
  14.  
  15. void *reallok(r, n)
  16.   void *r;
  17.   size_t n;
  18. {
  19.   r = realloc(r, n);
  20.   if (!r)
  21.     fatal("Out of memory -- cannot allocate %ld bytes", (unsigned long)n);
  22.   return r;
  23. }
  24.  
  25. #ifdef __STDC__
  26. void error(const char *fmt, ...)
  27. #else
  28. void error(fmt) const char *fmt;
  29. #endif
  30. {
  31.   va_list ap;
  32.  
  33.   fprintf(stderr, "%s:  ", argv0);
  34.   va_start(ap, fmt);
  35.   vfprintf(stderr, fmt, ap);
  36.   va_end(ap);
  37.   fputc('\n', stderr);
  38. }
  39.  
  40. #ifdef __STDC__
  41. void fatal(const char *fmt, ...)
  42. #else
  43. void fatal(fmt) const char *fmt;
  44. #endif
  45. {
  46.   va_list ap;
  47.  
  48.   fprintf(stderr, "%s: FATAL:  ", argv0);
  49.   va_start(ap, fmt);
  50.   vfprintf(stderr, fmt, ap);
  51.   va_end(ap);
  52.   fputc('\n', stderr);
  53.   exit(1);
  54. }
  55.  
  56. #ifdef __STDC__
  57. void bugchk(const char *fmt, ...)
  58. #else
  59. void bugchk(fmt) const char *fmt;
  60. #endif
  61. {
  62.   va_list ap;
  63.  
  64.   fprintf(stderr, "%s: internal error:  ", argv0);
  65.   va_start(ap, fmt);
  66.   vfprintf(stderr, fmt, ap);
  67.   va_end(ap);
  68.   fputc('\n', stderr);
  69.   exit(1);
  70. }
  71.